package com.aaa.controller.sds;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONUtil;
import com.aaa.controller.BaseController;
import com.aaa.entity.ReturnRecords;
import com.aaa.entity.system.PageEnty;
import com.aaa.entity.Result;
import com.aaa.entity.sds.ViewTestResultSds;
import com.aaa.entity.sds.ViewTestResultSdsTotal;
import com.aaa.entity.system.PageOrder;
import com.aaa.service.sds.ViewTestResultSdsService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * (ViewTestResultSds)表控制层
 *
 * @author makejava
 * @since 2022-09-02 09:49:58
 */
@RestController
@RequestMapping("viewTestResultSds")
public class ViewTestResultSdsController  extends BaseController {
    @Autowired
    ViewTestResultSdsService viewTestResultSdsService;

    /**
     * @create by: Teacher马
     * @description: 如果使用了restController注解，页面跳转不能使用上面的String
     * @create time:

     * @return
     */
    @RequestMapping("viewSdsUser.do")
    public ModelAndView viewSdsUser(ModelAndView modelAndView){
        modelAndView.setViewName("sds/showViewSds");
        return  modelAndView;
    }
    /**
     * @create by: Teacher马
     * @description:查询所有
     * @create time:

     * @return
     */
    @RequestMapping("queryAll.do")
    public String queryAll(PageEnty pageEnty, ViewTestResultSds viewTestResultSds){
        Page page = viewTestResultSdsService.queryAllViewSdsPage(pageEnty, viewTestResultSds);
        JSONConfig jsonConfig = JSONConfig.create().setDateFormat("yyyy-MM-dd HH:mm:ss");
        return JSONUtil.toJsonStr(success( page.getTotal(),page.getResult()),jsonConfig);
    }

    /**
     * @create by: Teacher马
     * @description:删除
     * @create time:

     * @return
     */
    @RequestMapping("deleteUser.do")
    public Result deleteUser(int[] id){
        boolean deleteUser = viewTestResultSdsService.deleteUser(id);
        if (deleteUser){
            return success();
        }else {
            return fail();
        }
    }
    /**
     * 通过主键查询单条数据
     *
     * @param
     * @return 单条数据
     */
    @RequestMapping("queryResult.do")
    public  Result queryById(Integer  id) {
        List<ViewTestResultSds> viewTestResultSds = viewTestResultSdsService.queryById(id);
        for (ViewTestResultSds viewTestResultSd : viewTestResultSds) {

            return success(viewTestResultSd);

        }
        return fail();
    }
    @RequestMapping("queryAllScl.do")
    public  Result queryAllScl() {
        List<ViewTestResultSdsTotal> viewTestResultSdsTotals = viewTestResultSdsService.queryAllSds();
        for (ViewTestResultSdsTotal viewTestResultSdsTotal : viewTestResultSdsTotals) {
            return success(viewTestResultSdsTotal);
        }
        return fail();
    }

    @RequestMapping("queryQuestionSDS.do")
    public Result getQuestionMHT(PageOrder pageOrder , Integer id) {
        Page<Map<String, Object>> byTesterId = viewTestResultSdsService.getByTesterId(pageOrder, id);
        if (ObjectUtil.isNotEmpty(byTesterId)) {
            return success(byTesterId.getTotal(), byTesterId.getResult());
        }
        return fail();
    }

    @RequestMapping("queryReturn.do")
    public Object queryReturn(PageOrder pageOrder , ReturnRecords records) {
        Page<ReturnRecords> byTesterId = viewTestResultSdsService.getReturnRecords(pageOrder, records);
        JSONConfig jsonConfig = JSONConfig.create();
        jsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
        String jsonStr = JSONUtil.toJsonStr(success(byTesterId.getTotal(), byTesterId.getResult()), jsonConfig);
        return jsonStr;
    }

    @RequestMapping("insertReturn.do")
    public Result insertReturn( ReturnRecords records) {
        int i = viewTestResultSdsService.insertReturn(records);
        if (i>0) {
            return success( );
        }
        return fail();
    }

    //用户查询页面
    @RequestMapping("toShowSDSReturn.do")
    public ModelAndView toShowMHTReturn(ModelAndView modelAndView){
        modelAndView.setViewName("sds/showSDSReturn");
        return modelAndView;
    }

}

